
import { useSelector } from 'react-redux'
import { Navigate } from 'react-router-dom'

const AuthRoute = ({ children, requiredRoles }) => {
    const { user } = useSelector(state => state.auth)

    if (!user) return <Navigate to="/login" />
    if (requiredRoles && !requiredRoles.includes(user.role)) {
        return <Navigate to="/403" />
    }

    return children
}

//路由中
<AuthRoute requiredRoles={['admin']}>
    <AdminPage />
</AuthRoute >
